package com.katze.boot.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.katze.boot.system.dao.UserSetupMapper;
import com.katze.boot.system.domain.UserSetup;
import com.katze.boot.system.service.UserSetupService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("userSetupService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserSetupServiceImpl extends ServiceImpl<UserSetupMapper, UserSetup> implements UserSetupService {

    @Override
    public UserSetup findByUsername(String username) {
        return this.baseMapper.selectByPrimaryKey(username);
    }

    @Override
    @Transactional
    public void initDefaultUserSetup(String username) {
        UserSetup userSetup = new UserSetup();
        userSetup.setUsername(username);
        userSetup.setColor("#409EFF");
        userSetup.setAffixContent(true);
        userSetup.setAffixSidebar(true);
        userSetup.setAffixLogo(true);
        userSetup.setAffixTabs(true);
        userSetup.setSidebarStyle("light");
        userSetup.setTabsStyle("style-1");
        userSetup.setUniqueOpened(true);
        userSetup.setTransition("fade");
        baseMapper.insert(userSetup);
    }

    @Override
    @Transactional
    public void deleteByUsername(String... usernames) {
        for (String username : usernames) {
            baseMapper.deleteByPrimaryKey(username);
        }
    }

    @Override
    @Transactional
    public void update(UserSetup userSetup) {
        baseMapper.updateByPrimaryKey(userSetup);
    }
}
